//package edu.johnpank.libassistant.config
//
//import edu.johnpank.libassistant.repo.UserRepository
//import edu.johnpank.libassistant.services.CustomUserDetailsService
//import org.springframework.beans.factory.annotation.Autowired
//import org.springframework.context.annotation.Bean
//import org.springframework.context.annotation.ComponentScan
//import org.springframework.context.annotation.Configuration
//import org.springframework.security.config.Customizer
//import org.springframework.security.config.Customizer.withDefaults
//import org.springframework.security.config.annotation.web.WebSecurityConfigurer
//import org.springframework.security.config.annotation.web.builders.HttpSecurity
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
//import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer
//import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer
//import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
//import org.springframework.security.core.userdetails.UserDetailsService
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
//import org.springframework.security.crypto.password.PasswordEncoder
//import org.springframework.security.web.SecurityFilterChain
//
//
//@Configuration
//@ComponentScan
//@EnableWebSecurity
//class WebSecurityConfig(
//    @Autowired
//    val userRepository: UserRepository,
//
//){
//    @Bean
//    @Throws(Exception::class)
//    fun configure(http: HttpSecurity): SecurityFilterChain? {
//        return http
//            .csrf { csrf: CsrfConfigurer<HttpSecurity> -> csrf.disable() }
//            .authorizeRequests(Customizer { auth: ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry ->
//                auth.antMatchers("/", "/login").permitAll()
//                auth.antMatchers("/user").hasRole("USER")
//                auth.antMatchers("/admin").hasRole("ADMIN")
//            })
//            .httpBasic(withDefaults())
//            .build()
//    }
//
//
//    @Bean
//    fun userDetailService(): UserDetailsService {
//        return UserDetailsService(){
//            return@UserDetailsService userRepository.findByEmail(it)
//        }
//    }
//
//
//    @Bean
//    fun passwordEncoder(): PasswordEncoder{
//        return BCryptPasswordEncoder(8)
//    }
//
//}
//
//
//
//
///*
//*    @Bean
////    @Throws(Exception::class)
////    fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
////        http
////            .authorizeHttpRequests(
////                Customizer { requests: AuthorizationManagerRequestMatcherRegistry ->
////                    requests
////                        .requestMatchers("/").permitAll()
////                        .anyRequest().authenticated()
////                }
////            )
////            .formLogin { form: FormLoginConfigurer<HttpSecurity?> ->
////                form
////                    .loginPage("/login")
////                    .permitAll()
////            }
////            .logout { logout: LogoutConfigurer<HttpSecurity?> -> logout.permitAll() }
////        return http.build()
////    }
////
////    @Bean
////    fun userDetailsService(): UserDetailsService {
////
////        val pwEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder()
////        val user = User.builder()
////            .username("user")
////            .password(pwEncoder.encode("password"))
////            .roles("USER")
////            .build()
////        return InMemoryUserDetailsManager(user)
////    }*/